/**
 * 作者: wgx
 * 日期: 2025-05-06 15:19:25
 * 备注: 用户大世界行军模块数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserWorldInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserWorldInfoModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户ID
    protected int energy; // 体力
    protected long energyTime; // 体力上次回复时间
    protected long eventRefreshTime; // 事件刷新时间 (有过0,8,16点才需要刷新)
    protected int eventNum; // 已完成的事件数量
    protected int eventLocationNum; // 已解锁的事件坑位数量 (系统整点刷新的事件坑位)
    protected int monsterLevel; // 怪兽等级，从队列显示事件时用，最小值1
    protected int monsterLevelMax; // 怪兽等级，从队列显示事件时用，历史最高值
    protected int eventLocationNumItem; // 已解锁的事件坑位数量 (使用道具121001生成额外事件)
    protected int eventLocationNumUrgent; // 已解锁的事件坑位数量 (紧急触发的事件，派遣部队时有概率触发)
    protected long resetTime; // 每日重置时间
    protected int urgentRefreshNum; // 紧急事件今日触发次数
    protected int energyBuyNum; // 体力购买次数 (每日重置)

    public void reset() {
    }

    protected String getKey() {
        return "UserWorldInfo." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_world_info"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户ID
        obj.put("energy", energy); // 体力
        obj.put("energyTime", energyTime); // 体力上次回复时间
        obj.put("eventRefreshTime", eventRefreshTime); // 事件刷新时间 (有过0,8,16点才需要刷新)
        obj.put("eventNum", eventNum); // 已完成的事件数量
        obj.put("eventLocationNum", eventLocationNum); // 已解锁的事件坑位数量 (系统整点刷新的事件坑位)
        obj.put("monsterLevel", monsterLevel); // 怪兽等级，从队列显示事件时用，最小值1
        obj.put("monsterLevelMax", monsterLevelMax); // 怪兽等级，从队列显示事件时用，历史最高值
        obj.put("eventLocationNumItem", eventLocationNumItem); // 已解锁的事件坑位数量 (使用道具121001生成额外事件)
        obj.put("eventLocationNumUrgent", eventLocationNumUrgent); // 已解锁的事件坑位数量 (紧急触发的事件，派遣部队时有概率触发)
        obj.put("resetTime", resetTime); // 每日重置时间
        obj.put("urgentRefreshNum", urgentRefreshNum); // 紧急事件今日触发次数
        obj.put("energyBuyNum", energyBuyNum); // 体力购买次数 (每日重置)
        return obj;
    }

    public PBUserWorldInfo.Builder takeInitBuilder() {
        PBUserWorldInfo.Builder sb = PBUserWorldInfo.newBuilder();
        if (energy != 0) {
            sb.setEnergy(energy);
        }
        if (energyTime != 0) {
            sb.setEnergyTime(energyTime);
        }
        if (energyBuyNum != 0) {
            sb.setEnergyBuyNum(energyBuyNum);
        }
        return sb;
    }

    public PBUserWorldInfo.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserWorldInfo.Builder sb = PBUserWorldInfo.newBuilder();
        if (isFieldUpdate("energy")) {
            sb.setEnergy(energy);
        }
        if (isFieldUpdate("energyTime")) {
            sb.setEnergyTime(energyTime);
        }
        if (isFieldUpdate("energyBuyNum")) {
            sb.setEnergyBuyNum(energyBuyNum);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getEnergy() {
        return energy;
    }

    public void putEnergy(int energy) {
        if (this.energy != energy) {
            this.energy = energy;
            updateRedisHashField(getKey(), "energy", this.energy);
        }
    }

    public void addEnergy(int value) {
        this.energy += value;
        updateRedisHashField(getKey(), "energy", this.energy);
    }

    public long getEnergyTime() {
        return energyTime;
    }

    public void putEnergyTime(long energyTime) {
        if (this.energyTime != energyTime) {
            this.energyTime = energyTime;
            updateRedisHashField(getKey(), "energyTime", this.energyTime);
        }
    }

    public void addEnergyTime(long value) {
        this.energyTime += value;
        updateRedisHashField(getKey(), "energyTime", this.energyTime);
    }

    public long getEventRefreshTime() {
        return eventRefreshTime;
    }

    public void putEventRefreshTime(long eventRefreshTime) {
        if (this.eventRefreshTime != eventRefreshTime) {
            this.eventRefreshTime = eventRefreshTime;
            updateRedisHashField(getKey(), "eventRefreshTime", this.eventRefreshTime);
        }
    }

    public void addEventRefreshTime(long value) {
        this.eventRefreshTime += value;
        updateRedisHashField(getKey(), "eventRefreshTime", this.eventRefreshTime);
    }

    public int getEventNum() {
        return eventNum;
    }

    public void putEventNum(int eventNum) {
        if (this.eventNum != eventNum) {
            this.eventNum = eventNum;
            updateRedisHashField(getKey(), "eventNum", this.eventNum);
        }
    }

    public void addEventNum(int value) {
        this.eventNum += value;
        updateRedisHashField(getKey(), "eventNum", this.eventNum);
    }

    public int getEventLocationNum() {
        return eventLocationNum;
    }

    public void putEventLocationNum(int eventLocationNum) {
        if (this.eventLocationNum != eventLocationNum) {
            this.eventLocationNum = eventLocationNum;
            updateRedisHashField(getKey(), "eventLocationNum", this.eventLocationNum);
        }
    }

    public void addEventLocationNum(int value) {
        this.eventLocationNum += value;
        updateRedisHashField(getKey(), "eventLocationNum", this.eventLocationNum);
    }

    public int getMonsterLevel() {
        return monsterLevel;
    }

    public void putMonsterLevel(int monsterLevel) {
        if (this.monsterLevel != monsterLevel) {
            this.monsterLevel = monsterLevel;
            updateRedisHashField(getKey(), "monsterLevel", this.monsterLevel);
        }
    }

    public void addMonsterLevel(int value) {
        this.monsterLevel += value;
        updateRedisHashField(getKey(), "monsterLevel", this.monsterLevel);
    }

    public int getMonsterLevelMax() {
        return monsterLevelMax;
    }

    public void putMonsterLevelMax(int monsterLevelMax) {
        if (this.monsterLevelMax != monsterLevelMax) {
            this.monsterLevelMax = monsterLevelMax;
            updateRedisHashField(getKey(), "monsterLevelMax", this.monsterLevelMax);
        }
    }

    public void addMonsterLevelMax(int value) {
        this.monsterLevelMax += value;
        updateRedisHashField(getKey(), "monsterLevelMax", this.monsterLevelMax);
    }

    public int getEventLocationNumItem() {
        return eventLocationNumItem;
    }

    public void putEventLocationNumItem(int eventLocationNumItem) {
        if (this.eventLocationNumItem != eventLocationNumItem) {
            this.eventLocationNumItem = eventLocationNumItem;
            updateRedisHashField(getKey(), "eventLocationNumItem", this.eventLocationNumItem);
        }
    }

    public void addEventLocationNumItem(int value) {
        this.eventLocationNumItem += value;
        updateRedisHashField(getKey(), "eventLocationNumItem", this.eventLocationNumItem);
    }

    public int getEventLocationNumUrgent() {
        return eventLocationNumUrgent;
    }

    public void putEventLocationNumUrgent(int eventLocationNumUrgent) {
        if (this.eventLocationNumUrgent != eventLocationNumUrgent) {
            this.eventLocationNumUrgent = eventLocationNumUrgent;
            updateRedisHashField(getKey(), "eventLocationNumUrgent", this.eventLocationNumUrgent);
        }
    }

    public void addEventLocationNumUrgent(int value) {
        this.eventLocationNumUrgent += value;
        updateRedisHashField(getKey(), "eventLocationNumUrgent", this.eventLocationNumUrgent);
    }

    public long getResetTime() {
        return resetTime;
    }

    public void putResetTime(long resetTime) {
        if (this.resetTime != resetTime) {
            this.resetTime = resetTime;
            updateRedisHashField(getKey(), "resetTime", this.resetTime);
        }
    }

    public void addResetTime(long value) {
        this.resetTime += value;
        updateRedisHashField(getKey(), "resetTime", this.resetTime);
    }

    public int getUrgentRefreshNum() {
        return urgentRefreshNum;
    }

    public void putUrgentRefreshNum(int urgentRefreshNum) {
        if (this.urgentRefreshNum != urgentRefreshNum) {
            this.urgentRefreshNum = urgentRefreshNum;
            updateRedisHashField(getKey(), "urgentRefreshNum", this.urgentRefreshNum);
        }
    }

    public void addUrgentRefreshNum(int value) {
        this.urgentRefreshNum += value;
        updateRedisHashField(getKey(), "urgentRefreshNum", this.urgentRefreshNum);
    }

    public int getEnergyBuyNum() {
        return energyBuyNum;
    }

    public void putEnergyBuyNum(int energyBuyNum) {
        if (this.energyBuyNum != energyBuyNum) {
            this.energyBuyNum = energyBuyNum;
            updateRedisHashField(getKey(), "energyBuyNum", this.energyBuyNum);
        }
    }

    public void addEnergyBuyNum(int value) {
        this.energyBuyNum += value;
        updateRedisHashField(getKey(), "energyBuyNum", this.energyBuyNum);
    }

}